﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Xml;
using Aulac.Rsc.Bss.Tags;
using Aulac.Rsc.Bss;

namespace Aulac.Client.Controls.Bss
{
	/// <summary>
	/// Summary description for MdnItemCtrl.
	/// </summary>
    [System.ComponentModel.ToolboxItem(true)]
    
    public partial class ComboMdnItem : Aulac.Client.Controls.UserControls.ComboTableCtrl
    {

        public ComboMdnItem()
		{
			InitializeComponent();
            OnInit();
		}

        //private void InitializeComponent()
        //{
        //    throw new NotImplementedException();
        //}
        protected override void OnFormLoad()
        {
            if (DesignMode) return;                        
            AutoLoadData = true;
            OnInit();
        }
        protected override void OnInit()
        {
            this.cboData.ColumnNames = string.Format("{0}, {1}", tagItems.Items.ItemID, tagItems.Items.ItemName);
            this.cboData.DisplayMember = tagItems.Items.ItemID;
            this.cboData.FieldMember = tagItems.MdnStore.StorePrkID;
            this.cboData.ValueMember = tagItems.Items.ItemID;
            this.cboData.ListFieldMember = string.Format("{0}, {1}", tagItems.MdnStore.StorePrkID, tagItems.Items.ItemName);
            this.cboData.LinkedColumnName = tagItems.Items.ItemName;
        }
        protected override void OnSetDataSource(out object pDataSource, out string pTableName)
        {
            pDataSource = new Aulac.Client.Data.Bss.DataSet.Catalog.Dm_MdnItemsDataTable();
            pTableName = TableNames.Dm_MdnItems;
        }

        protected override void OnAddParamsQuery()
        {
            //AddParamQuery(tagItems.CapAss.IsActive, tagItems.Icd.IsActive, DbType.Boolean, 1);
        }
    
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string ItemPrkID
		{
			get
			{
                return cboData.GetValueItem(tagItems.MdnStore.StorePrkID);
			}
			set
			{
                int index = cboData.FindItem(value, tagItems.Items.ItemPrkID);
                if (index >= 0)
                    cboData.SelectedIndex = index;
                else
                {
                    AutoLoadData = true;
                    ReLoadDataToControl();
                    index = cboData.FindItem(value, tagItems.Items.ItemPrkID);
                    if (index >= 0)
                        cboData.SelectedIndex = index;
                    else
                        cboData.SelectedIndex = -1;
                }
			}
		}


        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string ItemID
        {
            get
            {
                return cboData.GetValueItem(tagItems.Items.ItemID);
            }
            set
            {
                int index = cboData.FindItem(value, tagItems.Items.ItemID);
                if (index >= 0)
                    cboData.SelectedIndex = index;
                else
                {
                    AutoLoadData = true;
                    ReLoadDataToControl();
                    index = cboData.FindItem(value, tagItems.Items.ItemID);
                    if (index >= 0)
                        cboData.SelectedIndex = index;
                    else
                        cboData.SelectedIndex = -1;
                }
            }
        }

       

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

        public string ItemName
        {
            get
            {
                if (cboData.IsEmpty)
                    return "";
                return cboData.GetValueItem(tagItems.Items.ItemName);
            }
           
        }

    }
}
